#ifndef __BS_LORA_H
#define __BS_LORA_H

#include "main.h"
#include "system.h"
#define LoRo_RX_BUFFER_SIZE 80	

void LoRa_Modul_Inital(void);
typedef enum _LoRaRunATCmd{
	LORA_RUN_TEST = 0,
	LORA_RUN_RESET,
	LORA_RUN_SAVE,
	LORA_RUN_LINK,
	LORA_RUN_HEART,
}LoRaRunATCmd;

typedef enum _LoRaGetATCmd{
	LORA_GET_VERS = 0,
	LORA_GET_BAUD,
	LORA_GET_CONFIRM,
	LORA_GET_NBTRIALS,
	LORA_GET_ADR,
	LORA_GET_CLASS,
	LORA_GET_PORT,
	LORA_GET_SIGNAL,
	LORA_GET_DATARATE,
	LORA_GET_JOIN,
	LORA_GET_HEART,
	LORA_GET_CHANNEL,
	LORA_GET_DEVEUI,
	LORA_GET_APPEUI,
	LORA_GET_APPKEY,
	LORA_GET_POWER,
	LORA_GET_AUTO
}LoRaGetATCmd;

typedef enum _LoRaSetATCmd{
	LORA_SET_BAUD = 0,
	LORA_SET_CONFIRM,
	LORA_SET_NBTRIALS,
	LORA_SET_ADR,
	LORA_SET_CLASS,
	LORA_SET_PORT,
	LORA_SET_DATARATE,
	LORA_SET_SEND,
	LORA_SET_SENDCK,
	LORA_SET_JOIN,
	LORA_SET_SLEEP,
	LORA_SET_HEART,
	LORA_SET_CHANNEL,
	LORA_SET_APPEUI,
	LORA_SET_APPKEY,
	LORA_SET_POWER,
	LORA_SET_AUTO
}LoRaSetATCmd;
void LoRo_Uart_Init(u32 bound);
void LoRa_Uart_Send(const char *str, u32 size);
u16 LoRo_Uart_Receive(void **buffer);



void LoRaInit(void);




uint8 LoRaJoinNet(void);
char asciitohex(char high_ascii, char low_ascii);
char lowhextoascii(char hexdata);
void Lora_Tx_Data(char *str, u32 length);

void LoRo_Uart_CleanData(void);








void 	LoRaRunCmd(LoRaRunATCmd type);

void 	LoRaGetCmd(LoRaGetATCmd type);

void 	LoRaSetCmd(LoRaSetATCmd type, char* pArgs);
u8 		Set_Lora_Join(void);
u8 		Check_Lora_Join_Status(void);
void 	Lora_Tx_Data(char* str, u32 length);
char 	asciitohex(char high_ascii,char low_ascii);
uint8 	ConvertStringToHex(uint8 *str);

char 	lowhextoascii(char hexdata);
void	SetLoRaModeToWorkClassC(void);
uint8 	LoRaSendDada(CollectedData *data);
uint8  	LoRaCmdProcess(void);
uint8	ReturnAckToServer(uint8 errorcode);
uint8	LoRaModeReset(void);
uint8	LoRaSleepMode(uint8	Flag);
uint8 	LoRaGetBuzzerCmd(uint16	*cmd);
void 	LoRo_Uart_Init(u32 bound);
void 	LoraHardwareReset(void);
UINT8	GetLoraDEVEUI(uint8		*deveuibuffer);
uint8 	ReceiveCmdFromServer(uint8*Recebuffer);
void	CmdPorcess(uint8	*Recebuffer);
uint8 	JudegWhetherSendingSuccessful(void);
uint8	SendAckToServer(uint8	CmdCode);


extern	char gLoraSetBuffer[50];
extern	char *gptrLoraRx; 

extern	__IO	u8 gLoRaRxFlag;		 



#define	ErrCode_Success		0
#define	ErrCode_Fail		1
#define	ErrCode_Busy		2
#define	ErrCode_ReceData	3

#define	NotBeepOFF			0X77
#define	LongBeepOFF			0XAA
#define	ShortBeepOFF		0X55
#endif
